home *** CD-ROM | disk | FTP | other *** search
/ Aminet 49 / Aminet 49 (2002)(GTI - Schatztruhe)[!][Jun 2002].iso / Aminet / util / misc / ReportPlus.lha / ReportPlus / source / f4.c < prev    next >
C/C++ Source or Header  |  2002-04-15  |  69KB  |  1,638 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <proto/exec.h>
  4. #include <intuition/intuition.h>
  5. #include <intuition/gadgetclass.h>
  6. #include <proto/intuition.h>
  7. #include <libraries/gadtools.h>
  8. #include <proto/gadtools.h>
  9.  
  10. #include <ctype.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include "rp.h"
  14.  
  15. #define ALL_REACTION_CLASSES
  16. #include <reaction/reaction.h>
  17. #include <clib/texteditor_protos.h>
  18. #include <gadgets/texteditor.h>
  19. #include <pragmas/texteditor_pragmas.h>
  20.  
  21. #define MAXELEMENTS_4 14 // counting from 0
  22.  
  23. MODULE void bizarre(void);
  24. MODULE void updateautodocgadgets(void);
  25. MODULE void readautodocgadgets(void);
  26. MODULE void starify(STRPTR buffer);
  27. MODULE void destarify(STRPTR buffer);
  28. MODULE ULONG parseeither(STRPTR terminator1, STRPTR terminator2);
  29. MODULE void numberofinputs(void);
  30.  
  31. MODULE UBYTE*               StarBufferPtr = NULL;
  32. MODULE ULONG                elements,
  33.                             returncode,
  34.                             inputs;
  35. MODULE struct Gadget*       autodoc_gadgets[GIDS_4 + 1];
  36.  
  37. /* Current limitations:
  38.   * 4K characters per text editor field. This limitation is
  39.     not currently enforced by the program. Ideally we would like to use
  40.     TEXTEDITOR_MaxChars or suchlike. Using strncpy() with a limit of 4K
  41.     when reading from the text editor gadgets or reading from a file would
  42.     also be good.
  43.   * 16K characters for the entire autodoc. */
  44.  
  45. AGLOBAL struct AutodocStruct autodoc;
  46.  
  47. IMPORT struct Menu*        MenuPtr;
  48. IMPORT Object*             WinObject[FUNCTIONS + 1];
  49. IMPORT struct Screen*      ScreenPtr;
  50. IMPORT struct Window*      MainWindowPtr;
  51. IMPORT struct SharedStruct shared;
  52. IMPORT struct Library*     TextEditorBase;
  53.  
  54. IMPORT SBYTE               page;
  55. IMPORT TEXT                aslresult[MEDFIELD + 1],
  56.                            IOBuffer[LONGESTFIELD + 1],
  57.                            string[VLONGFIELD + 1];
  58. IMPORT ULONG               offset;
  59.  
  60. AGLOBAL void autodoc1(void)
  61. {   struct Hook Hook4Struct;
  62.  
  63.     /* Create the window object. */
  64.     lockscreen();
  65.     gadtools();
  66.     InitHook(&Hook4Struct, Hook4Func, NULL);
  67.  
  68.     if (!(WinObject[4] =
  69.     NewObject
  70.     (   WINDOW_GetClass(),            NULL,
  71.         WA_PubScreen,                 ScreenPtr,
  72.         WA_ScreenTitle,               "Report+",
  73.         WA_Title,                     "Report+: Autodoc Editor (Page 1 of 2)",
  74.         WA_Activate,                  TRUE,
  75.         WA_DepthGadget,               TRUE,
  76.         WA_DragBar,                   TRUE,
  77.         WA_CloseGadget,               TRUE,
  78.         WA_SizeGadget,                TRUE,
  79.         WA_IDCMP,                     IDCMP_RAWKEY,
  80.         WINDOW_IDCMPHook,             &Hook4Struct,
  81.         WINDOW_IDCMPHookBits,         IDCMP_RAWKEY,
  82.         WINDOW_MenuStrip,             MenuPtr,
  83.         WINDOW_Position,              WPOS_CENTERSCREEN,
  84.         WINDOW_ParentGroup,           autodoc_gadgets[GID_4_LY1] =
  85.         NewObject
  86.         (   LAYOUT_GetClass(), NULL,
  87.             // root-layout
  88.             LAYOUT_Orientation,        LAYOUT_ORIENT_VERT,
  89.             LAYOUT_SpaceOuter,         TRUE,
  90.             LAYOUT_DeferLayout,        TRUE,
  91.             LAYOUT_AddChild,
  92.             NewObject
  93.             (   LAYOUT_GetClass(),     NULL,
  94.                 LAYOUT_Orientation,    LAYOUT_ORIENT_HORIZ,
  95.                 LAYOUT_SpaceOuter,     TRUE,
  96.                 LAYOUT_VertAlignment,  LALIGN_CENTER,
  97.                 LAYOUT_HorizAlignment, LALIGN_CENTER,
  98.                 LAYOUT_BevelStyle,     BVS_FIELD,
  99.                 LAYOUT_AddChild,
  100.                 NewObject
  101.                 (   LAYOUT_GetClass(),     NULL,
  102.                     LAYOUT_Orientation,    LAYOUT_ORIENT_VERT,
  103.                     LAYOUT_SpaceOuter,     TRUE,
  104.                     LAYOUT_VertAlignment,  LALIGN_CENTER,
  105.                     LAYOUT_HorizAlignment, LALIGN_CENTER,
  106.                     LAYOUT_BevelStyle,     BVS_NONE,
  107.                     LAYOUT_AddImage,
  108.                     NewObject
  109.                     (   LABEL_GetClass(),  NULL,
  110.                         LABEL_Text,        "modulename._type:",
  111.                         LABEL_Justification,LJ_LEFT,
  112.                     TAG_END),
  113.                     CHILD_WeightedHeight,  0,
  114.                     LAYOUT_AddImage,
  115.                     NewObject
  116.                     (   LABEL_GetClass(),  NULL,
  117.                         LABEL_Text,        "Function_Name:",
  118.                         LABEL_Justification,LJ_LEFT,
  119.                     TAG_END),
  120.                     CHILD_WeightedHeight,  0,
  121.                     LAYOUT_AddImage,
  122.                     NewObject
  123.                     (   LABEL_GetClass(),  NULL,
  124.                         LABEL_Text,        "_Description:",
  125.                         LABEL_Justification,LJ_LEFT,
  126.                     TAG_END),
  127.                     CHILD_WeightedHeight,   0,
  128.                 TAG_END),
  129.                 CHILD_WeightedWidth,       0,
  130.                 LAYOUT_AddChild,
  131.                 NewObject
  132.                 (   LAYOUT_GetClass(),     NULL,
  133.                     LAYOUT_Orientation,    LAYOUT_ORIENT_VERT,
  134.                     LAYOUT_SpaceOuter,     TRUE,
  135.                     LAYOUT_VertAlignment,  LALIGN_CENTER,
  136.                     LAYOUT_HorizAlignment, LALIGN_CENTER,
  137.                     LAYOUT_BevelStyle,     BVS_NONE,
  138.                     LAYOUT_AddChild,
  139.                     NewObject
  140.                     (   LAYOUT_GetClass(),     NULL,
  141.                         LAYOUT_Orientation,    LAYOUT_ORIENT_HORIZ,
  142.                         LAYOUT_SpaceOuter,     TRUE,
  143.                         LAYOUT_VertAlignment,  LALIGN_CENTER,
  144.                         LAYOUT_HorizAlignment, LALIGN_CENTER,
  145.                         LAYOUT_BevelStyle,     BVS_NONE,
  146.                         LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST1] =
  147.                         NewObject
  148.                         (   STRING_GetClass(), NULL,
  149.                             GA_ID,             GID_4_ST1,
  150.                             GA_RelVerify,      TRUE,
  151.                             GA_TabCycle,       TRUE,
  152.                             STRINGA_TextVal,   autodoc.library,
  153.                             STRINGA_MinVisible,15,
  154.                             STRINGA_MaxChars,  MEDFIELD,
  155.                         TAG_END),
  156.                         CHILD_WeightedWidth,   50,
  157.                         LAYOUT_AddImage,
  158.                         NewObject
  159.                         (   LABEL_GetClass(),  NULL,
  160.                             LABEL_Text,        "Minimum _version:",
  161.                             LABEL_Justification,LJ_LEFT,
  162.                         TAG_END),
  163.                         CHILD_WeightedWidth,   0,
  164.                         LAYOUT_AddChild,       autodoc_gadgets[GID_4_IN1] =
  165.                         NewObject
  166.                         (   INTEGER_GetClass(),   NULL,
  167.                             GA_ID,                GID_4_IN1,
  168.                             GA_RelVerify,         TRUE,
  169.                             GA_TabCycle,          TRUE,
  170.                             INTEGER_Number,       autodoc.version,
  171.                             INTEGER_Minimum,      0, // ULONG (maximum value is (2^32) - 1)
  172.                             INTEGER_MinVisible,   5,
  173.                             TAG_END
  174.                         ),                                      
  175.                         CHILD_WeightedWidth,      50,
  176.                     TAG_END),
  177.                     CHILD_WeightedHeight,      0,
  178.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST2] =
  179.                     NewObject
  180.                     (   STRING_GetClass(), NULL,
  181.                         GA_ID,             GID_4_ST2,
  182.                         GA_RelVerify,      TRUE,
  183.                         GA_TabCycle,       TRUE,
  184.                         STRINGA_TextVal,   autodoc.funcname,
  185.                         STRINGA_MinVisible,35,
  186.                         STRINGA_MaxChars,  MEDFIELD,
  187.                     TAG_END),
  188.                     CHILD_WeightedHeight,  0,
  189.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST3] =
  190.                     NewObject
  191.                     (   STRING_GetClass(), NULL,
  192.                         GA_ID,             GID_4_ST3,
  193.                         GA_RelVerify,      TRUE,
  194.                         GA_TabCycle,       TRUE,
  195.                         STRINGA_TextVal,   autodoc.description,
  196.                         STRINGA_MinVisible,35,
  197.                         STRINGA_MaxChars,  VLONGFIELD,
  198.                     TAG_END),
  199.                     CHILD_WeightedHeight,  0,
  200.                 TAG_END),
  201.                 CHILD_WeightedWidth,       100,
  202.             TAG_END),
  203.             CHILD_WeightedHeight,          0,
  204.             LAYOUT_AddChild,
  205.             NewObject
  206.             (   LAYOUT_GetClass(),     NULL,
  207.                 LAYOUT_Orientation,    LAYOUT_ORIENT_HORIZ,
  208.                 LAYOUT_SpaceOuter,     TRUE,
  209.                 LAYOUT_VertAlignment,  LALIGN_LEFT,
  210.                 LAYOUT_HorizAlignment, LALIGN_RIGHT,
  211.                 LAYOUT_BevelStyle,     BVS_NONE,
  212.                 LAYOUT_AddChild,
  213.                 NewObject
  214.                 (   LAYOUT_GetClass(),     NULL,
  215.                     LAYOUT_Orientation,    LAYOUT_ORIENT_VERT,
  216.                     LAYOUT_SpaceOuter,     TRUE,
  217.                     LAYOUT_VertAlignment,  LALIGN_CENTER,
  218.                     LAYOUT_HorizAlignment, LALIGN_CENTER,
  219.                     LAYOUT_BevelStyle,     BVS_NONE,
  220.                     LAYOUT_AddImage,
  221.                     NewObject
  222.                     (   LABEL_GetClass(),  NULL,
  223.                         LABEL_Text,        "",
  224.                         LABEL_Justification,LJ_CENTER,
  225.                     TAG_END),
  226.                     LAYOUT_AddImage,
  227.                     NewObject
  228.                     (   LABEL_GetClass(),  NULL,
  229.                         LABEL_Text,        "_Return code:",
  230.                         LABEL_Justification,LJ_CENTER,
  231.                     TAG_END),
  232.                     LAYOUT_AddImage,
  233.                     NewObject
  234.                     (   LABEL_GetClass(),  NULL,
  235.                         LABEL_Text,        "Argument _1:",
  236.                         LABEL_Justification,LJ_CENTER,
  237.                     TAG_END),
  238.                     LAYOUT_AddImage,
  239.                     NewObject
  240.                     (   LABEL_GetClass(),  NULL,
  241.                         LABEL_Text,        "Argument _2:",
  242.                         LABEL_Justification,LJ_CENTER,
  243.                     TAG_END),
  244.                     LAYOUT_AddImage,
  245.                     NewObject
  246.                     (   LABEL_GetClass(),  NULL,
  247.                         LABEL_Text,        "Argument _3:",
  248.                         LABEL_Justification,LJ_CENTER,
  249.                     TAG_END),
  250.                     LAYOUT_AddImage,
  251.                     NewObject
  252.                     (   LABEL_GetClass(),  NULL,
  253.                         LABEL_Text,        "Argument _4:",
  254.                         LABEL_Justification,LJ_CENTER,
  255.                     TAG_END),
  256.                     LAYOUT_AddImage,
  257.                     NewObject
  258.                     (   LABEL_GetClass(),  NULL,
  259.                         LABEL_Text,        "Argument _5:",
  260.                         LABEL_Justification,LJ_CENTER,
  261.                     TAG_END),
  262.                     LAYOUT_AddImage,
  263.                     NewObject
  264.                     (   LABEL_GetClass(),  NULL,
  265.                         LABEL_Text,        "Argument _6:",
  266.                         LABEL_Justification,LJ_CENTER,
  267.                     TAG_END),
  268.                     LAYOUT_AddImage,
  269.                     NewObject
  270.                     (   LABEL_GetClass(),  NULL,
  271.                         LABEL_Text,        "Argument _7:",
  272.                         LABEL_Justification,LJ_CENTER,
  273.                     TAG_END),
  274.                     LAYOUT_AddImage,
  275.                     NewObject
  276.                     (   LABEL_GetClass(),  NULL,
  277.                         LABEL_Text,        "Argument _8:",
  278.                         LABEL_Justification,LJ_CENTER,
  279.                     TAG_END),
  280.                 TAG_END),
  281.                 CHILD_WeightedWidth,       0,
  282.                 LAYOUT_AddChild,
  283.                 NewObject
  284.                 (   LAYOUT_GetClass(),     NULL,
  285.                     LAYOUT_Orientation,    LAYOUT_ORIENT_VERT,
  286.                     LAYOUT_SpaceOuter,     TRUE,
  287.                     LAYOUT_VertAlignment,  LALIGN_CENTER,
  288.                     LAYOUT_HorizAlignment, LALIGN_CENTER,
  289.                     LAYOUT_BevelStyle,     BVS_NONE,
  290.                     LAYOUT_AddImage,
  291.                     NewObject
  292.                     (   LABEL_GetClass(),  NULL,
  293.                         LABEL_Text,        "Type",
  294.                         LABEL_Justification,LJ_CENTER,
  295.                     TAG_END),
  296.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST4] =
  297.                     NewObject
  298.                     (   STRING_GetClass(), NULL,
  299.                         GA_ID,             GID_4_ST4,
  300.                         GA_RelVerify,      TRUE,
  301.                         GA_TabCycle,       TRUE,
  302.                         STRINGA_TextVal,   autodoc.var[0].type,
  303.                         STRINGA_MinVisible,8,
  304.                         STRINGA_MaxChars,  MEDFIELD,
  305.                     TAG_END),
  306.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST5] =
  307.                     NewObject
  308.                     (   STRING_GetClass(), NULL,
  309.                         GA_ID,             GID_4_ST5,
  310.                         GA_RelVerify,      TRUE,
  311.                         GA_TabCycle,       TRUE,
  312.                         STRINGA_TextVal,   autodoc.var[1].type,
  313.                         STRINGA_MinVisible,8,
  314.                         STRINGA_MaxChars,  MEDFIELD,
  315.                     TAG_END),
  316.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST6] =
  317.                     NewObject
  318.                     (   STRING_GetClass(), NULL,
  319.                         GA_ID,             GID_4_ST6,
  320.                         GA_RelVerify,      TRUE,
  321.                         GA_TabCycle,       TRUE,
  322.                         STRINGA_TextVal,   autodoc.var[2].type,
  323.                         STRINGA_MinVisible,8,
  324.                         STRINGA_MaxChars,  MEDFIELD,
  325.                     TAG_END),
  326.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST7] =
  327.                     NewObject
  328.                     (   STRING_GetClass(), NULL,
  329.                         GA_ID,             GID_4_ST7,
  330.                         GA_RelVerify,      TRUE,
  331.                         GA_TabCycle,       TRUE,
  332.                         STRINGA_TextVal,   autodoc.var[3].type,
  333.                         STRINGA_MinVisible,8,
  334.                         STRINGA_MaxChars,  MEDFIELD,
  335.                     TAG_END),
  336.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST8] =
  337.                     NewObject
  338.                     (   STRING_GetClass(), NULL,
  339.                         GA_ID,             GID_4_ST8,
  340.                         GA_RelVerify,      TRUE,
  341.                         GA_TabCycle,       TRUE,
  342.                         STRINGA_TextVal,   autodoc.var[4].type,
  343.                         STRINGA_MinVisible,8,
  344.                         STRINGA_MaxChars,  MEDFIELD,
  345.                     TAG_END),
  346.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST9] =
  347.                     NewObject
  348.                     (   STRING_GetClass(), NULL,
  349.                         GA_ID,             GID_4_ST9,
  350.                         GA_RelVerify,      TRUE,
  351.                         GA_TabCycle,       TRUE,
  352.                         STRINGA_TextVal,   autodoc.var[5].type,
  353.                         STRINGA_MinVisible,8,
  354.                         STRINGA_MaxChars,  MEDFIELD,
  355.                     TAG_END),
  356.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST10] =
  357.                     NewObject
  358.                     (   STRING_GetClass(), NULL,
  359.                         GA_ID,             GID_4_ST10,
  360.                         GA_RelVerify,      TRUE,
  361.                         GA_TabCycle,       TRUE,
  362.                         STRINGA_TextVal,   autodoc.var[6].type,
  363.                         STRINGA_MinVisible,8,
  364.                         STRINGA_MaxChars,  MEDFIELD,
  365.                     TAG_END),
  366.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST11] =
  367.                     NewObject
  368.                     (   STRING_GetClass(), NULL,
  369.                         GA_ID,             GID_4_ST11,
  370.                         GA_RelVerify,      TRUE,
  371.                         GA_TabCycle,       TRUE,
  372.                         STRINGA_TextVal,   autodoc.var[7].type,
  373.                         STRINGA_MinVisible,8,
  374.                         STRINGA_MaxChars,  MEDFIELD,
  375.                     TAG_END),
  376.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST12] =
  377.                     NewObject
  378.                     (   STRING_GetClass(), NULL,
  379.                         GA_ID,             GID_4_ST12,
  380.                         GA_RelVerify,      TRUE,
  381.                         GA_TabCycle,       TRUE,
  382.                         STRINGA_TextVal,   autodoc.var[8].type,
  383.                         STRINGA_MinVisible,8,
  384.                         STRINGA_MaxChars,  MEDFIELD,
  385.                     TAG_END),
  386.                 TAG_END),
  387.                 CHILD_WeightedWidth,       35,
  388.                 LAYOUT_AddChild,
  389.                 NewObject
  390.                 (   LAYOUT_GetClass(),     NULL,
  391.                     LAYOUT_Orientation,    LAYOUT_ORIENT_VERT,
  392.                     LAYOUT_SpaceOuter,     TRUE,
  393.                     LAYOUT_VertAlignment,  LALIGN_CENTER,
  394.                     LAYOUT_HorizAlignment, LALIGN_CENTER,
  395.                     LAYOUT_BevelStyle,     BVS_NONE,
  396.                     LAYOUT_AddImage,
  397.                     NewObject
  398.                     (   LABEL_GetClass(),  NULL,
  399.                         LABEL_Text,        "Name",
  400.                         LABEL_Justification,LJ_CENTER,
  401.                     TAG_END),
  402.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST13] =
  403.                     NewObject
  404.                     (   STRING_GetClass(), NULL,
  405.                         GA_ID,             GID_4_ST13,
  406.                         GA_RelVerify,      TRUE,
  407.                         GA_TabCycle,       TRUE,
  408.                         STRINGA_TextVal,   autodoc.var[0].name,
  409.                         STRINGA_MinVisible,8,
  410.                         STRINGA_MaxChars,  MEDFIELD,
  411.                     TAG_END),
  412.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST14] =
  413.                     NewObject
  414.                     (   STRING_GetClass(), NULL,
  415.                         GA_ID,             GID_4_ST14,
  416.                         GA_RelVerify,      TRUE,
  417.                         GA_TabCycle,       TRUE,
  418.                         STRINGA_TextVal,   autodoc.var[1].name,
  419.                         STRINGA_MinVisible,8,
  420.                         STRINGA_MaxChars,  MEDFIELD,
  421.                     TAG_END),
  422.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST15] =
  423.                     NewObject
  424.                     (   STRING_GetClass(), NULL,
  425.                         GA_ID,             GID_4_ST15,
  426.                         GA_RelVerify,      TRUE,
  427.                         GA_TabCycle,       TRUE,
  428.                         STRINGA_TextVal,   autodoc.var[2].name,
  429.                         STRINGA_MinVisible,8,
  430.                         STRINGA_MaxChars,  MEDFIELD,
  431.                     TAG_END),
  432.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST16] =
  433.                     NewObject
  434.                     (   STRING_GetClass(), NULL,
  435.                         GA_ID,             GID_4_ST16,
  436.                         GA_RelVerify,      TRUE,
  437.                         GA_TabCycle,       TRUE,
  438.                         STRINGA_TextVal,   autodoc.var[3].name,
  439.                         STRINGA_MinVisible,8,
  440.                         STRINGA_MaxChars,  MEDFIELD,
  441.                     TAG_END),
  442.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST17] =
  443.                     NewObject
  444.                     (   STRING_GetClass(), NULL,
  445.                         GA_ID,             GID_4_ST17,
  446.                         GA_RelVerify,      TRUE,
  447.                         GA_TabCycle,       TRUE,
  448.                         STRINGA_TextVal,   autodoc.var[4].name,
  449.                         STRINGA_MinVisible,8,
  450.                         STRINGA_MaxChars,  MEDFIELD,
  451.                     TAG_END),
  452.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST18] =
  453.                     NewObject
  454.                     (   STRING_GetClass(), NULL,
  455.                         GA_ID,             GID_4_ST18,
  456.                         GA_RelVerify,      TRUE,
  457.                         GA_TabCycle,       TRUE,
  458.                         STRINGA_TextVal,   autodoc.var[5].name,
  459.                         STRINGA_MinVisible,8,
  460.                         STRINGA_MaxChars,  MEDFIELD,
  461.                     TAG_END),
  462.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST19] =
  463.                     NewObject
  464.                     (   STRING_GetClass(), NULL,
  465.                         GA_ID,             GID_4_ST19,
  466.                         GA_RelVerify,      TRUE,
  467.                         GA_TabCycle,       TRUE,
  468.                         STRINGA_TextVal,   autodoc.var[6].name,
  469.                         STRINGA_MinVisible,8,
  470.                         STRINGA_MaxChars,  MEDFIELD,
  471.                     TAG_END),
  472.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST20] =
  473.                     NewObject
  474.                     (   STRING_GetClass(), NULL,
  475.                         GA_ID,             GID_4_ST20,
  476.                         GA_RelVerify,      TRUE,
  477.                         GA_TabCycle,       TRUE,
  478.                         STRINGA_TextVal,   autodoc.var[7].name,
  479.                         STRINGA_MinVisible,8,
  480.                         STRINGA_MaxChars,  MEDFIELD,
  481.                     TAG_END),
  482.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST21] =
  483.                     NewObject
  484.                     (   STRING_GetClass(), NULL,
  485.                         GA_ID,             GID_4_ST21,
  486.                         GA_RelVerify,      TRUE,
  487.                         GA_TabCycle,       TRUE,
  488.                         STRINGA_TextVal,   autodoc.var[8].name,
  489.                         STRINGA_MinVisible,8,
  490.                         STRINGA_MaxChars,  MEDFIELD,
  491.                     TAG_END),
  492.                 TAG_END),
  493.                 CHILD_WeightedWidth,       50,
  494.                 LAYOUT_AddChild,
  495.                 NewObject
  496.                 (   LAYOUT_GetClass(),     NULL,
  497.                     LAYOUT_Orientation,    LAYOUT_ORIENT_VERT,
  498.                     LAYOUT_SpaceOuter,     TRUE,
  499.                     LAYOUT_VertAlignment,  LALIGN_CENTER,
  500.                     LAYOUT_HorizAlignment, LALIGN_CENTER,
  501.                     LAYOUT_BevelStyle,     BVS_NONE,
  502.                     LAYOUT_AddImage,
  503.                     NewObject
  504.                     (   LABEL_GetClass(),  NULL,
  505.                         LABEL_Text,        "Register",
  506.                         LABEL_Justification,LJ_CENTER,
  507.                     TAG_END),
  508.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST22] =
  509.                     NewObject
  510.                     (   STRING_GetClass(), NULL,
  511.                         GA_ID,             GID_4_ST22,
  512.                         GA_RelVerify,      TRUE,
  513.                         GA_TabCycle,       TRUE,
  514.                         STRINGA_TextVal,   autodoc.var[0].reg,
  515.                         STRINGA_MinVisible,8,
  516.                         STRINGA_MaxChars,  MEDFIELD,
  517.                     TAG_END),
  518.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST23] =
  519.                     NewObject
  520.                     (   STRING_GetClass(), NULL,
  521.                         GA_ID,             GID_4_ST23,
  522.                         GA_RelVerify,      TRUE,
  523.                         GA_TabCycle,       TRUE,
  524.                         STRINGA_TextVal,   autodoc.var[1].reg,
  525.                         STRINGA_MinVisible,8,
  526.                         STRINGA_MaxChars,  MEDFIELD,
  527.                     TAG_END),
  528.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST24] =
  529.                     NewObject
  530.                     (   STRING_GetClass(), NULL,
  531.                         GA_ID,             GID_4_ST24,
  532.                         GA_RelVerify,      TRUE,
  533.                         GA_TabCycle,       TRUE,
  534.                         STRINGA_TextVal,   autodoc.var[2].reg,
  535.                         STRINGA_MinVisible,8,
  536.                         STRINGA_MaxChars,  MEDFIELD,
  537.                     TAG_END),
  538.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST25] =
  539.                     NewObject
  540.                     (   STRING_GetClass(), NULL,
  541.                         GA_ID,             GID_4_ST25,
  542.                         GA_RelVerify,      TRUE,
  543.                         GA_TabCycle,       TRUE,
  544.                         STRINGA_TextVal,   autodoc.var[3].reg,
  545.                         STRINGA_MinVisible,8,
  546.                         STRINGA_MaxChars,  MEDFIELD,
  547.                     TAG_END),
  548.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST26] =
  549.                     NewObject
  550.                     (   STRING_GetClass(), NULL,
  551.                         GA_ID,             GID_4_ST26,
  552.                         GA_RelVerify,      TRUE,
  553.                         GA_TabCycle,       TRUE,
  554.                         STRINGA_TextVal,   autodoc.var[4].reg,
  555.                         STRINGA_MinVisible,8,
  556.                         STRINGA_MaxChars,  MEDFIELD,
  557.                     TAG_END),
  558.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST27] =
  559.                     NewObject
  560.                     (   STRING_GetClass(), NULL,
  561.                         GA_ID,             GID_4_ST27,
  562.                         GA_RelVerify,      TRUE,
  563.                         GA_TabCycle,       TRUE,
  564.                         STRINGA_TextVal,   autodoc.var[5].reg,
  565.                         STRINGA_MinVisible,8,
  566.                         STRINGA_MaxChars,  MEDFIELD,
  567.                     TAG_END),
  568.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST28] =
  569.                     NewObject
  570.                     (   STRING_GetClass(), NULL,
  571.                         GA_ID,             GID_4_ST28,
  572.                         GA_RelVerify,      TRUE,
  573.                         GA_TabCycle,       TRUE,
  574.                         STRINGA_TextVal,   autodoc.var[6].reg,
  575.                         STRINGA_MinVisible,8,
  576.                         STRINGA_MaxChars,  MEDFIELD,
  577.                     TAG_END),
  578.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST29] =
  579.                     NewObject
  580.                     (   STRING_GetClass(), NULL,
  581.                         GA_ID,             GID_4_ST29,
  582.                         GA_RelVerify,      TRUE,
  583.                         GA_TabCycle,       TRUE,
  584.                         STRINGA_TextVal,   autodoc.var[7].reg,
  585.                         STRINGA_MinVisible,8,
  586.                         STRINGA_MaxChars,  MEDFIELD,
  587.                     TAG_END),
  588.                     LAYOUT_AddChild,       autodoc_gadgets[GID_4_ST30] =
  589.                     NewObject
  590.                     (   STRING_GetClass(), NULL,
  591.                         GA_ID,             GID_4_ST30,
  592.                         GA_RelVerify,      TRUE,
  593.                         GA_TabCycle,       TRUE,
  594.                         STRINGA_TextVal,   autodoc.var[8].reg,
  595.                         STRINGA_MinVisible,8,
  596.                         STRINGA_MaxChars,  MEDFIELD,
  597.                     TAG_END),
  598.                 TAG_END),
  599.                 CHILD_WeightedWidth,       15,
  600.             TAG_END),
  601.             CHILD_WeightedHeight,      0,
  602.             LAYOUT_AddChild,          autodoc_gadgets[GID_4_BU1] =
  603.             NewObject
  604.             (   NULL,                 "button.gadget",
  605.                 // button
  606.                 GA_ID,                GID_4_BU1,
  607.                 GA_RelVerify,         TRUE,
  608.                 GA_Text,              "_Other page",
  609.             TAG_END),
  610.             CHILD_WeightedHeight,         0,
  611.         TAG_END
  612.     ))))
  613.     {   rq("Can't create ReAction objects!");
  614.     }
  615.     unlockscreen();
  616.     openwindow();
  617.     OnMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_NEW,    NOSUB));
  618.     OnMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_OPEN,   NOSUB));
  619.     OnMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_SAVE,   NOSUB));
  620.     OnMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_SAVEAS, NOSUB));
  621.     ActivateLayoutGadget(autodoc_gadgets[GID_4_LY1], MainWindowPtr, NULL, (Object) autodoc_gadgets[GID_4_ST1]);
  622.  
  623.     loop();
  624.     closewindow();
  625. }
  626.  
  627. AGLOBAL void saveautodoc(ABOOL saveas)
  628. {   ULONG i, j;
  629.     TEXT  temp[MEDFIELD + 1];
  630.     SWORD size;
  631.  
  632.     readautodocgadgets();
  633.    
  634.     strcpy(IOBuffer, "/" "****** ");        //  1:  "/###### "
  635.     strcat(IOBuffer, autodoc.library);      //  1:  "/###### <library>"
  636.     strcat(IOBuffer, "/");                  //  1:  "/###### <library>/"
  637.     strcat(IOBuffer, autodoc.funcname);     //  1:  "/###### <library>/<funcname>"
  638.     strcat(IOBuffer, " ");                  //  1:  "/###### <library>/<funcname> "
  639.  
  640.     size = 67 - strlen(autodoc.library) - strlen(autodoc.funcname);
  641.     if (size > 0)
  642.     {   for (i = 1; i <= size; i++)           
  643.             strcat(IOBuffer, "*");          //  1:  "/###### <library>/<funcname> <stars>"
  644.     }
  645.  
  646.     strcat(IOBuffer, "\n*\n*   NAME\n*   ");
  647.                                             //  1:  "/###### <library>/<funcname> <stars>\n"
  648.                                             //  2:  "#\n"
  649.                                             //  3:  "#   NAME\n"
  650.                                             //  4:  "#   "
  651.     strcat(IOBuffer, autodoc.funcname);     //  4:  "#   <funcname>"
  652.     strcat(IOBuffer, " -- ");               //  4:  "#   <funcname> -- "
  653.     strcat(IOBuffer, autodoc.description);
  654.                                             //  4:  "#   <funcname> -- <description>"
  655.     if (autodoc.version)
  656.     {   strcat(IOBuffer, " (V");            //  4:  "#   <funcname> -- <description>[ (V]"
  657.         stcl_d(temp, autodoc.version);
  658.         strcat(IOBuffer, temp);             //  4:  "#   <funcname> -- <description>[ (V<version>]"
  659.         strcat(IOBuffer, ")");              //  4:  "#   <funcname> -- <description>[ (V<version>)]
  660.     }
  661.     strcat(IOBuffer, "\n*\n*   SYNOPSIS\n");
  662.                                             //  4:  "#   <funcname> -- <description>[ (V<version>)]\n"
  663.                                             //  5:  "#\n"
  664.                                             //  6:  "#   SYNOPSIS\n"
  665.  
  666.     // name line
  667.     strcat(IOBuffer, "*   ");               //  7:  "#   "
  668.     if (autodoc.var[0].name[0])
  669.     {   strcat(IOBuffer, autodoc.var[0].name);
  670.                                             //  7:  "#   [<returnname>]"
  671.         strcat(IOBuffer, " = ");            //  7:  "#   [<returnname> = ]"
  672.     }
  673.     strcat(IOBuffer, autodoc.funcname);     //  7:  "#   [<returnname> = ]<funcname>"
  674.     strcat(IOBuffer, "(");                  //  7:  "#   [<returnname> = ]<funcname>("
  675.  
  676.     for (i = 1; i <= 8; i++)
  677.     {   if (autodoc.var[i].name[0])
  678.         {   if (i >= 2)
  679.                 strcat(IOBuffer, ", ");
  680.             strcat(IOBuffer, autodoc.var[i].name);
  681.             size = strlen(autodoc.var[i].reg) - strlen(autodoc.var[i].name);
  682.             if (size > 0)
  683.                 for (j = 1; j <= size; j++)
  684.                     strcat(IOBuffer, " ");
  685.         } else break;
  686.     }
  687.     strcat(IOBuffer, ")\n");                //  7:  "#   [<returnname> = ]<funcname>([<arglist>])\n"
  688.  
  689.     // register line
  690.     strcat(IOBuffer, "*   ");               //  8:  "#   "
  691.     if (autodoc.var[0].reg[0] && autodoc.var[0].name[0])
  692.     {   strcat(IOBuffer, autodoc.var[0].reg);
  693.                                             //  8:  "#   [<returnreg>]"
  694.         size = strlen(autodoc.var[0].name) - strlen(autodoc.var[0].reg);
  695.         if (size > 0)
  696.             for (i = 1; i <= size; i++)
  697.                 strcat(IOBuffer, " ");      //  8:  "#   [<returnreg><spaces>]"
  698.         strcat(IOBuffer, "   ");            //  8:  "#   [<returnreg><spaces>   ]"
  699.     }
  700.     size = strlen(autodoc.funcname);
  701.     if (size >= 0) // this is no mistake
  702.         for (i = 0; i <= size; i++)
  703.             strcat(IOBuffer, " ");          //  8:  "#   [<returnreg><spaces>   ]<spaces>"
  704.  
  705.     for (i = 1; i <= 8; i++)
  706.     {   if (autodoc.var[i].reg[0])
  707.         {   if (i >= 2)
  708.                 strcat(IOBuffer, "  ");
  709.             strcat(IOBuffer, autodoc.var[i].reg);
  710.             size = strlen(autodoc.var[i].name) - strlen(autodoc.var[i].reg);
  711.             if (size > 0)
  712.                 for (j = 1; j <= size; j++)
  713.                     strcat(IOBuffer, " ");
  714.     }   }
  715.     strcat(IOBuffer, "\n");                 //  8:  "#   [<returnreg><spaces>   ]<spaces>[<reglist>]\n"
  716.  
  717.     strcat(IOBuffer, "*\n*   ");            //  9:  "#\n"
  718.                                             // 10:  "#   "
  719.     if (autodoc.var[0].type[0])
  720.     {   strcat(IOBuffer, autodoc.var[0].type);
  721.                                             // 10a: "#   <returntype>"
  722.         strcat(IOBuffer, " ");              // 10a: "#   <returntype> "
  723.     } else
  724.         strcat(IOBuffer, "void ");          // 10b: "#   void "
  725.     strcat(IOBuffer, autodoc.funcname);     // 10:  "#   <returntype>|void <funcname>"
  726.     strcat(IOBuffer, "(");                  // 10:  "#   <returntype>|void <funcname>("
  727.     if (!(autodoc.var[1].type))             // 10:  "#   <returntype>|void <funcname>([void]"
  728.         strcat(IOBuffer, "void");
  729.     else
  730.     {   for (i = 1; i <= 8; i++)
  731.         {   if (autodoc.var[i].type[0])
  732.             {   if (i >= 2)
  733.                     strcat(IOBuffer, ", ");
  734.                 strcat(IOBuffer, autodoc.var[i].type);
  735.             } else break;
  736.     }   }
  737.     strcat(IOBuffer, ");\n*\n*   FUNCTION\n*   ");
  738.                                             // 10:  "#   <returntype>|void <funcname>(void|<typelist>);\n"
  739.                                             // 11:  "#\n"
  740.                                             // 12:  "#   FUNCTION\n"
  741.                                             // 13:  "#   "
  742.     starify(autodoc.function);
  743.     strcat(IOBuffer, StarBufferPtr);        // 13:  "#   <buffer>"
  744.     FreeVec(StarBufferPtr);
  745.  
  746.     strcat(IOBuffer, "\n*\n*   INPUTS\n");  // 13:  "#   <buffer>\n"
  747.                                             // 14:  "#\n"
  748.                                             // 15:  "#   INPUTS\n"
  749.  
  750.     bizarre();
  751.  
  752.     strcat(IOBuffer, "*\n*   RESULT\n*   ");
  753.                                             // 17:  "#\n"
  754.                                             // 18:  "#   RESULT\n"
  755.                                             // 19:  "#   "
  756.     if (!(autodoc.var[0].name[0]))
  757.     {   strcat(IOBuffer, "NONE");           // 19a: "#   NONE"
  758.     } else
  759.     {   strcat(IOBuffer, autodoc.var[0].name);
  760.                                             // 19b: "#   <returnname>"
  761.         strcat(IOBuffer, " - ");            // 19b: "#   <returnname> - "
  762.  
  763.         starify(autodoc.var[0].desc);
  764.         strcat(IOBuffer, StarBufferPtr);    // 19b: "#   <returnname> - <buffer>"
  765.         FreeVec(StarBufferPtr);
  766.     }
  767.  
  768.     strcat
  769.     (   IOBuffer,
  770.         "\n*\n"                             // 19a: "#   NONE\n"
  771.                                             // 19b: "#   <returnname> - <buffer>\n"
  772.                                             // 20:  "#\n"
  773.         "*   EXAMPLE\n*   "                 // 21:  "#   EXAMPLE\n"
  774.                                             // 22:  "#   "
  775.     );
  776.  
  777.     starify(autodoc.example);
  778.     strcat(IOBuffer, StarBufferPtr);        // 22:  "#   <buffer>"
  779.     FreeVec(StarBufferPtr);
  780.     strcat(IOBuffer, "\n*\n*   NOTES\n*   ");
  781.                                             // 22:  "#   <buffer>\n"
  782.                                             // 23:  "#\n"
  783.                                             // 24:  "#   NOTES\n"
  784.                                             // 25:  "#   "
  785.     starify(autodoc.notes);
  786.     strcat(IOBuffer, StarBufferPtr);        // 25:  "#   <buffer>"
  787.     FreeVec(StarBufferPtr);
  788.     strcat(IOBuffer, "\n*\n*   BUGS\n*   ");
  789.                                             // 25:  "#   <buffer>\n"
  790.                                             // 26:  "#\n"
  791.                                             // 27:  "#   BUGS\n"
  792.                                             // 28:  "#   "
  793.     starify(autodoc.bugs);
  794.     strcat(IOBuffer, StarBufferPtr);        // 28:  "#   <buffer>"
  795.     FreeVec(StarBufferPtr);
  796.     strcat(IOBuffer, "\n*\n*   SEE ALSO\n*   ");
  797.                                             // 28:  "#   <buffer>\n"
  798.                                             // 29:  "#\n"
  799.                                             // 30:  "#   SEE ALSO\n"
  800.                                             // 31:  "#   "
  801.     starify(autodoc.seealso);
  802.     strcat(IOBuffer, StarBufferPtr);        // 31:  "#   <buffer>"
  803.     FreeVec(StarBufferPtr);
  804.  
  805.     strcat
  806.     (   IOBuffer,
  807.         "\n*\n"                             // 31:  "#   <buffer>\n"
  808.                                             // 32:  "#\n"
  809.         "*****************************************************************************\n"
  810.                                             // 33:  "<77 stars>\n"
  811.         "*\n*"                              // 34:  "#\n"
  812.                                             // 35:  "#"
  813.         "/\n"                               // 35:  "#/\n"
  814.     );
  815.  
  816.     if (!autodoc.output[0] || saveas) // if we need a filename
  817.     {   if (saveasl("Save Autodoc", "#?.c"))
  818.         {   strcpy(autodoc.output, aslresult);
  819.             writeout(autodoc.output);
  820.     }   }
  821.     else
  822.     {   writeout(autodoc.output);
  823. }   }
  824.  
  825. MODULE void bizarre(void)
  826. {   ULONG i, j;
  827.     SWORD size, longest = 0, thislength; // must be signed
  828.     TEXT  line[VLONGFIELD + 1]; // better not make it too large, as it is
  829.                                 // a local (stack) variable.
  830.  
  831.     numberofinputs();
  832.     if (!inputs)
  833.     {   strcpy(line, "*   NONE\n");         // 16:  "#   NONE\n"
  834.     } else
  835.     {   for (i = 1; i <= inputs; i++)
  836.         {   thislength = strlen(autodoc.var[i].name);
  837.             if (thislength > longest)
  838.             {   longest = thislength;
  839.         }   }
  840.  
  841.         for (i = 1; i <= inputs; i++)
  842.         {   strcpy(line, "*   ");           // 16:  "#   "
  843.             strcat(line, autodoc.var[i].name);
  844.                                             // 16:  "#   <argname1>"
  845.             thislength = strlen(autodoc.var[i].name);
  846.             size = longest - thislength;
  847.             if (size > 0)
  848.             {   for (j = 1; j <= size; j++)
  849.                 {    strcat(line, " ");     // 16:  "#   <argname1><spaces>"
  850.             }   }
  851.             strcat(line, " - ");            // 16:  "#   <argname1><spaces> - "
  852.  
  853.             starify(autodoc.var[i].desc);
  854.             strcat(line, StarBufferPtr);
  855.             FreeVec(StarBufferPtr);                     // 16:  "#   <argname1><spaces> - <buffer1>"
  856.             strcat(line, "\n");             // 16:  "#   <argname1><spaces> - <buffer1>\n"
  857.             strcat(IOBuffer, line);
  858. }   }   }
  859.  
  860. AGLOBAL void newautodoc(ABOOL display)
  861. {   ULONG i;
  862.  
  863.     autodoc.version        = 0;
  864.     autodoc.library[0]     = 0;
  865.     autodoc.funcname[0]    = 0;
  866.     autodoc.description[0] = 0;
  867.     for (i = 0; i <= 8; i++)
  868.     {   autodoc.var[i].name[0] = 0;
  869.         autodoc.var[i].type[0] = 0;
  870.         autodoc.var[i].reg[0]  = 0;
  871.         autodoc.var[i].desc[0] = 0;
  872.     }
  873.     autodoc.output[0]   = 0;
  874.     autodoc.function[0] = 0;
  875.     autodoc.example[0]  = 0;
  876.     autodoc.notes[0]    = 0;
  877.     autodoc.bugs[0]     = 0;
  878.     autodoc.seealso[0]  = 0;
  879.  
  880.     if (display)
  881.     {   updateautodocgadgets();
  882. }   }
  883.  
  884. AGLOBAL void openautodoc(void)
  885. {   if (asl("~(#?.info)"))
  886.     {   newautodoc(FALSE); // This line and the next are order-dependant
  887.         strcpy(autodoc.output, aslresult);
  888.         loadautodoc();
  889.         updateautodocgadgets();
  890. }   }
  891.  
  892. AGLOBAL void loadautodoc(void)
  893. {   ULONG counter, i, whatfound;
  894.  
  895.     /* parse() returns when it has moved along and found the specified
  896.        `ending string'. The contents, since last parse(), before the
  897.        `ending string' are returned in string. */
  898.  
  899.     if (readin(autodoc.output))
  900.     {   offset = 0;
  901.         parse("/" "****** "); // skip header
  902.  
  903.         // name
  904.         parse("/");
  905.         strcpy(autodoc.library, string);
  906.         parse(" ");
  907.         strcpy(autodoc.funcname, string);
  908.         parse("\n*\n*   NAME\n*   "); 
  909.  
  910.         // ignore that, skip all the asterisks
  911.         parse(" -- ");
  912.         // function name is repeated here
  913.         if (parseeither(" (V", "\n*\n*   SYNOPSIS\n*   ") == 1)
  914.         {   strcpy(autodoc.description, string);
  915.             parse(")\n*\n*   SYNOPSIS\n*   ");
  916.             autodoc.version = atol(string);
  917.         } else
  918.         {   strcpy(autodoc.description, string);
  919.         }
  920.  
  921.         // synopsis
  922.         if (parseeither(" = ", "(") == 1)
  923.         {   strcpy(autodoc.var[0].name, string);
  924.             parse("(");
  925.         }
  926.         // function name is repeated here
  927.         counter = 0;
  928.         while (whatfound = parseeither(", ", ")\n*   "))
  929.         {   if (string[0]) // in case we get () situation (ie. no args)
  930.             {   counter++;
  931.                 strcpy(autodoc.var[counter].name, string);
  932.             }
  933.             if (whatfound == 2)
  934.             {   break;
  935.         }   }
  936.         inputs = counter;
  937.         if (autodoc.var[0].name[0])
  938.         {   counter = 0;
  939.         } else counter = 1; // where to start
  940.         while (whatfound = parseeither(" ", "\n*\n*   "))
  941.         {   if (string[0])
  942.             {   strcpy(autodoc.var[counter].reg, string);
  943.                 counter++;
  944.             }
  945.             if (whatfound == 2)
  946.             {   break;
  947.         }   }
  948.         parse(" ");
  949.         strcpy(autodoc.var[0].type, string);
  950.         parse("(");
  951.         // function name is repeated here
  952.         counter = 0;
  953.         while (whatfound = parseeither(", ", ");\n*\n*   FUNCTION\n*   "))
  954.         {   if (string[0]) // in case we get () situation (ie. no args)
  955.             {   counter++;
  956.                 strcpy(autodoc.var[counter].type, string);
  957.             }
  958.             if (whatfound == 2)
  959.             {   break;
  960.         }   }
  961.         // function
  962.         parse("\n*\n*   INPUTS\n*   ");
  963.         destarify(string);
  964.         strcpy(autodoc.function, StarBufferPtr);
  965.         FreeVec(StarBufferPtr);
  966.  
  967.         // inputs
  968.         for (i = 1; i <= inputs; i++)
  969.         {   parse("   ");
  970.             parse(" -");
  971.             // input name is repeated here
  972.             if (parseeither(" ", "\n*") == 1)
  973.             {   parse("\n*");
  974.                 destarify(string);
  975.                 strcpy(autodoc.var[counter].desc, StarBufferPtr);
  976.                 FreeVec(StarBufferPtr);
  977.         }   } 
  978.         parse("\n*   RESULT\n*   ");
  979.  
  980.         // result
  981.         if (parseeither(" - ", "NONE\n*\n*   EXAMPLE\n*   ") == 1)
  982.         {   strcpy(autodoc.var[0].name, string);
  983.             parse("\n*\n*   EXAMPLE");
  984.             destarify(string);
  985.             strcpy(autodoc.var[0].desc, StarBufferPtr);
  986.             FreeVec(StarBufferPtr);
  987.             parseeither("\n*   ", "S\n*   "); // accepts either EXAMPLE or EXAMPLES
  988.         }
  989.  
  990.         // example
  991.         parse("\n*\n*   NOTES\n*   ");
  992.         destarify(string);
  993.         strcpy(autodoc.example, StarBufferPtr);
  994.         FreeVec(StarBufferPtr);
  995.  
  996.         // notes
  997.         parse("\n*\n*   BUGS\n*   ");
  998.         destarify(string);
  999.         strcpy(autodoc.notes, StarBufferPtr);
  1000.         FreeVec(StarBufferPtr);
  1001.  
  1002.         // bugs
  1003.         parse("\n*\n*   SEE ALSO\n*   ");
  1004.         destarify(string);
  1005.         strcpy(autodoc.bugs, StarBufferPtr);
  1006.         FreeVec(StarBufferPtr);
  1007.  
  1008.         // see also
  1009.         parse("\n*\n*****************************************************************************\n*\n*" "/" "\n");
  1010.         destarify(string);
  1011.         strcpy(autodoc.seealso, StarBufferPtr);
  1012.         FreeVec(StarBufferPtr);
  1013. }   }
  1014.  
  1015. AGLOBAL void autodoc_init(void)
  1016. {   newautodoc(FALSE);
  1017. }
  1018.  
  1019. AGLOBAL void autodoc_loop(ULONG gid)
  1020. {   STRPTR stringptr;
  1021.  
  1022.     switch(gid)
  1023.     {
  1024.     case GID_4_ST1:
  1025.         if (!(GetAttr
  1026.         (   STRINGA_TextVal, autodoc_gadgets[GID_4_ST1], (ULONG *) &stringptr
  1027.         )))
  1028.         {   rq("Unsupported inquiry!"); // should never happen
  1029.         }
  1030.         strcpy(autodoc.library, stringptr);
  1031.     break;
  1032.     case GID_4_ST2:
  1033.         if (!(GetAttr
  1034.         (   STRINGA_TextVal, autodoc_gadgets[GID_4_ST2], (ULONG *) &stringptr
  1035.         )))
  1036.         {   rq("Unsupported inquiry!"); // should never happen
  1037.         }
  1038.         strcpy(autodoc.funcname, stringptr);
  1039.     break;
  1040.     case GID_4_ST3:
  1041.         if (!(GetAttr
  1042.         (   STRINGA_TextVal, autodoc_gadgets[GID_4_ST3], (ULONG *) &stringptr
  1043.         )))
  1044.         {   rq("Unsupported inquiry!"); // should never happen
  1045.         }
  1046.         strcpy(autodoc.description, stringptr);
  1047.     break;
  1048.     case GID_4_IN1:
  1049.         if (!(GetAttr
  1050.         (   INTEGER_Number, autodoc_gadgets[GID_4_IN1], (ULONG *) &autodoc.version
  1051.         )))
  1052.         {   rq("Unsupported inquiry!"); // should never happen
  1053.         }
  1054.     break;
  1055.     case GID_4_BU1:
  1056.         readautodocgadgets();
  1057.         numberofinputs();
  1058.         page = 42;
  1059.     break;
  1060.     case GID_4_BU3:
  1061.         readautodocgadgets();
  1062.         page = 41;
  1063.     break;
  1064.     default:
  1065.         if (gid >= GID_4_ST4 && gid <= GID_4_ST4 + 8)
  1066.         {   if (!(GetAttr
  1067.             (   STRINGA_TextVal, autodoc_gadgets[gid], (ULONG *) &stringptr
  1068.             )))
  1069.             {   rq("Unsupported inquiry!"); // should never happen
  1070.             }
  1071.             strcpy(autodoc.var[gid - GID_4_ST4].type, stringptr);
  1072.         } elif (gid >= GID_4_ST13 && gid <= GID_4_ST13 + 8)
  1073.         {   if (!(GetAttr
  1074.             (   STRINGA_TextVal, autodoc_gadgets[gid], (ULONG *) &stringptr
  1075.             )))
  1076.             {   rq("Unsupported inquiry!"); // should never happen
  1077.             }
  1078.             strcpy(autodoc.var[gid - GID_4_ST13].name, stringptr);
  1079.         } elif (gid >= GID_4_ST22 && gid <= GID_4_ST22 + 8)
  1080.         {   if (!(GetAttr
  1081.             (   STRINGA_TextVal, autodoc_gadgets[gid], (ULONG *) &stringptr
  1082.             )))
  1083.             {   rq("Unsupported inquiry!"); // should never happen
  1084.             }
  1085.             strcpy(autodoc.var[gid - GID_4_ST22].reg, stringptr);
  1086.         }
  1087.         break;
  1088. }   }
  1089.  
  1090. MODULE void updateautodocgadgets(void)
  1091. {   ULONG i;
  1092.  
  1093. if (page == 41)
  1094. {   SetGadgetAttrs
  1095.     (   autodoc_gadgets[GID_4_ST1], MainWindowPtr, NULL,
  1096.         STRINGA_TextVal, autodoc.library,
  1097.         TAG_END
  1098.     );
  1099.     SetGadgetAttrs
  1100.     (   autodoc_gadgets[GID_4_ST2], MainWindowPtr, NULL,
  1101.         STRINGA_TextVal, autodoc.funcname,
  1102.         TAG_END
  1103.     );
  1104.     SetGadgetAttrs
  1105.     (   autodoc_gadgets[GID_4_ST3], MainWindowPtr, NULL,
  1106.         STRINGA_TextVal, autodoc.description,
  1107.         TAG_END
  1108.     );
  1109.     SetGadgetAttrs
  1110.     (   autodoc_gadgets[GID_4_IN1], MainWindowPtr, NULL,
  1111.         INTEGER_Number, autodoc.version,
  1112.         TAG_END
  1113.     );
  1114.  
  1115.     for (i = 0; i <= 8; i++)
  1116.     {   SetGadgetAttrs
  1117.         (   autodoc_gadgets[GID_4_ST4 + i], MainWindowPtr, NULL,
  1118.             STRINGA_TextVal, autodoc.var[i].type,
  1119.             TAG_END
  1120.         );
  1121.         SetGadgetAttrs
  1122.         (   autodoc_gadgets[GID_4_ST13 + i], MainWindowPtr, NULL,
  1123.             STRINGA_TextVal, autodoc.var[i].name,
  1124.             TAG_END
  1125.         );
  1126.         SetGadgetAttrs
  1127.         (   autodoc_gadgets[GID_4_ST22 + i], MainWindowPtr, NULL,
  1128.             STRINGA_TextVal, autodoc.var[i].reg,
  1129.             TAG_END
  1130.         );
  1131. }   }
  1132. else
  1133. {   ; /* assert(page == 42);
  1134.     This should never be called, because New and Open... are only
  1135.     available from page 41. */
  1136. }
  1137. }
  1138.  
  1139. MODULE void readautodocgadgets(void)
  1140. {   ULONG  i;
  1141.     STRPTR stringptr;
  1142.     STRPTR textBuffer[MAXELEMENTS_4 + 1];
  1143.  
  1144. if (page == 41)
  1145. {   if (!(GetAttr
  1146.     (   STRINGA_TextVal, autodoc_gadgets[GID_4_ST1], (ULONG *) &stringptr
  1147.     )))
  1148.     {   rq("Unsupported inquiry!"); // should never happen
  1149.     }
  1150.     strcpy(autodoc.library, stringptr);
  1151.  
  1152.     if (!(GetAttr
  1153.     (   STRINGA_TextVal, autodoc_gadgets[GID_4_ST2], (ULONG *) &stringptr
  1154.     )))
  1155.     {   rq("Unsupported inquiry!"); // should never happen
  1156.     }
  1157.     strcpy(autodoc.funcname, stringptr);
  1158.  
  1159.     if (!(GetAttr
  1160.     (   STRINGA_TextVal, autodoc_gadgets[GID_4_ST3], (ULONG *) &stringptr
  1161.     )))
  1162.     {   rq("Unsupported inquiry!"); // should never happen
  1163.     }
  1164.     strcpy(autodoc.description, stringptr);
  1165.  
  1166.     if (!(GetAttr
  1167.     (   INTEGER_Number, autodoc_gadgets[GID_4_IN1], (ULONG *) &autodoc.version
  1168.     )))
  1169.     {   rq("Unsupported inquiry!"); // should never happen
  1170.     }
  1171.  
  1172.     for (i = 0; i <= 8; i++)
  1173.     {   if (!(GetAttr
  1174.         (   STRINGA_TextVal, autodoc_gadgets[GID_4_ST4 + i], (ULONG *) &stringptr
  1175.         )))
  1176.         {   rq("Unsupported inquiry!"); // should never happen
  1177.         }
  1178.         strcpy(autodoc.var[i].type, stringptr);
  1179.  
  1180.         if (!(GetAttr
  1181.         (   STRINGA_TextVal, autodoc_gadgets[GID_4_ST13 + i], (ULONG *) &stringptr
  1182.         )))
  1183.         {   rq("Unsupported inquiry!"); // should never happen
  1184.         }
  1185.         strcpy(autodoc.var[i].name, stringptr);
  1186.  
  1187.         if (!(GetAttr
  1188.         (   STRINGA_TextVal, autodoc_gadgets[GID_4_ST22 + i], (ULONG *) &stringptr
  1189.         )))
  1190.         {   rq("Unsupported inquiry!"); // should never happen
  1191.         }
  1192.         strcpy(autodoc.var[i].reg, stringptr);
  1193. }   }
  1194. else
  1195. {   // assert(page == 42);
  1196.     for (i = 0; i <= elements; i++)
  1197.     {   textBuffer[i] = (STRPTR) DoGadgetMethod(autodoc_gadgets[GID_4_TE1 + i], MainWindowPtr, NULL, GM_TEXTEDITOR_ExportText, NULL);
  1198.     }
  1199.     strcpy(autodoc.function, textBuffer[0]);
  1200.     if (inputs)
  1201.     {   for (i = 1; i <= inputs; i++)
  1202.         {   strcpy(autodoc.var[i].desc, textBuffer[i]);
  1203.     }   }
  1204.     if (returncode)
  1205.     {   strcpy(autodoc.var[0].desc, textBuffer[inputs + 1]);
  1206.     }
  1207.     strcpy(autodoc.example, textBuffer[inputs + returncode + 1]);
  1208.     strcpy(autodoc.notes,   textBuffer[inputs + returncode + 2]);
  1209.     strcpy(autodoc.bugs,    textBuffer[inputs + returncode + 3]);
  1210.     strcpy(autodoc.seealso, textBuffer[inputs + returncode + 4]);
  1211.     for (i = 0; i <= elements; i++)
  1212.     {   FreeVec((APTR) textBuffer[i]);
  1213.         textBuffer[i] = NULL;
  1214. }   }
  1215. }
  1216.  
  1217. MODULE void starify(STRPTR buffer)
  1218. {   ULONG i, inputlength = 0, outputlength = 0, outputpos = 0;
  1219.     ABOOL done = FALSE;
  1220.  
  1221.     // first we count the number of LFs in the source buffer, and the
  1222.     // length of the source buffer.
  1223.     while (!done)
  1224.     {   if (*(buffer + inputlength) == LF)
  1225.             outputlength += 4;
  1226.         elif (*(buffer + inputlength) == 0)
  1227.             done = TRUE;
  1228.         outputlength++;
  1229.         inputlength++;
  1230.     }
  1231.  
  1232.     // now we allocate the buffer
  1233.     if (!(StarBufferPtr = AllocVec(outputlength, MEMF_PUBLIC)))
  1234.         rq("Out of memory!");
  1235.  
  1236.     // now we translate into new buffer
  1237.     for (i = 0; i <= inputlength; i++)
  1238.     {   *(StarBufferPtr + outputpos) = *(buffer + i);
  1239.         if (*(buffer + i) == LF)
  1240.         {   *(StarBufferPtr + outputpos + 1) = '*';
  1241.             *(StarBufferPtr + outputpos + 2) = ' ';
  1242.             *(StarBufferPtr + outputpos + 3) = ' ';
  1243.             *(StarBufferPtr + outputpos + 4) = ' ';
  1244.             outputpos += 4;
  1245.         }
  1246.         outputpos++;
  1247. }   }
  1248. MODULE void destarify(STRPTR buffer)
  1249. {   ULONG i, inputlength = 0, outputlength = 0, outputpos = 0;
  1250.     ABOOL done = FALSE;
  1251.  
  1252.     // Translates occurrences of "\n*   " to " ".
  1253.     while (!done) // first pass
  1254.     {   if (!strncmp(buffer + inputlength, "\n*   ", 5))
  1255.             outputlength -= 4; // we replace 5 bytes with 1, saving 4 bytes
  1256.         elif (*(buffer + inputlength) == 0)
  1257.             done = TRUE;
  1258.         outputlength++;
  1259.         inputlength++;
  1260.     }
  1261.  
  1262.     // now we allocate the buffer
  1263.     if (!(StarBufferPtr = AllocVec(outputlength, MEMF_PUBLIC)))
  1264.         rq("Out of memory!");
  1265.  
  1266.     // now we translate into new buffer
  1267.     for (i = 0; i <= inputlength; i++) // second pass
  1268.     {   if (!strncmp(buffer + i, "\n*   ", 5))
  1269.         {   // currently we are at the LF.
  1270.             *(StarBufferPtr + outputpos) = ' ';
  1271.             i += 4; // plus the usual 1 incremented by the loop
  1272.         } else
  1273.         {   *(StarBufferPtr + outputpos) = *(buffer + i);
  1274.         }
  1275.         outputpos++;
  1276. }   }
  1277.  
  1278. AGLOBAL ULONG Hook4Func(struct Hook *h, VOID *o, VOID *msg)
  1279. {   /* "When the hook is called, the data argument points to the
  1280.     window object and message argument to the IntuiMessage." */
  1281.  
  1282.     UWORD code, qual;
  1283.  
  1284.     geta4(); // wait till here before doing anything
  1285.     code = ((struct IntuiMessage *) msg)->Code;
  1286.     qual = ((struct IntuiMessage *) msg)->Qualifier;
  1287.     switch(code)
  1288.     {
  1289.     case SCAN_HELP:
  1290.         helpabout();
  1291.     break;
  1292.     case SCAN_ESCAPE:
  1293.         if ((qual & IEQUALIFIER_LSHIFT) || (qual & IEQUALIFIER_RSHIFT))
  1294.         {   cleanexit(EXIT_SUCCESS);
  1295.         } else
  1296.         {   page = 0;
  1297.         }
  1298.     break;
  1299.     case SCAN_B:
  1300.         if (page == 42)
  1301.         {   ActivateLayoutGadget(autodoc_gadgets[GID_4_LY2], MainWindowPtr, NULL, (Object) autodoc_gadgets[GID_4_TE1 + inputs + returncode + 3]);
  1302.         }
  1303.     break;
  1304.     case SCAN_D:
  1305.         if (page == 41)
  1306.         {   ActivateLayoutGadget(autodoc_gadgets[GID_4_LY1], MainWindowPtr, NULL, (Object) autodoc_gadgets[GID_4_ST3]);
  1307.         }
  1308.     break;
  1309.     case SCAN_E:
  1310.         if (page == 42)
  1311.         {   ActivateLayoutGadget(autodoc_gadgets[GID_4_LY2], MainWindowPtr, NULL, (Object) autodoc_gadgets[GID_4_TE1 + inputs + returncode + 1]);
  1312.         }
  1313.     break;
  1314.     case SCAN_F:
  1315.         if (page == 42)
  1316.         {   ActivateLayoutGadget(autodoc_gadgets[GID_4_LY2], MainWindowPtr, NULL, (Object) autodoc_gadgets[GID_4_TE1]);
  1317.         }
  1318.     break;
  1319.     case SCAN_N:
  1320.         if (page == 41)
  1321.         {   ActivateLayoutGadget(autodoc_gadgets[GID_4_LY1], MainWindowPtr, NULL, (Object) autodoc_gadgets[GID_4_ST2]);
  1322.         } else
  1323.         {   // assert(page == 42);
  1324.             ActivateLayoutGadget(autodoc_gadgets[GID_4_LY2], MainWindowPtr, NULL, (Object) autodoc_gadgets[GID_4_TE1 + inputs + returncode + 2]);
  1325.         }
  1326.     break;
  1327.     case SCAN_T:
  1328.         if (page == 41)
  1329.         {   ActivateLayoutGadget(autodoc_gadgets[GID_4_LY1], MainWindowPtr, NULL, (Object) autodoc_gadgets[GID_4_ST1]);
  1330.         }
  1331.     break;
  1332.     case SCAN_R:
  1333.         if (page == 41)
  1334.         {   ActivateLayoutGadget(autodoc_gadgets[GID_4_LY1], MainWindowPtr, NULL, (Object) autodoc_gadgets[GID_4_ST4]);
  1335.         } else
  1336.         {   // assert(page == 42);
  1337.             if (returncode)
  1338.             {   ActivateLayoutGadget(autodoc_gadgets[GID_4_LY2], MainWindowPtr, NULL, (Object) autodoc_gadgets[GID_4_TE1 + inputs + 1]);
  1339.         }   }
  1340.     break;
  1341.     case SCAN_S:
  1342.         if (page == 42)
  1343.         {   ActivateLayoutGadget(autodoc_gadgets[GID_4_LY2], MainWindowPtr, NULL, (Object) autodoc_gadgets[GID_4_TE1 + inputs + returncode + 4]);
  1344.         }
  1345.     break;
  1346.     case SCAN_V:
  1347.         if (page == 41)
  1348.         {   ActivateLayoutGadget(autodoc_gadgets[GID_4_LY1], MainWindowPtr, NULL, (Object) autodoc_gadgets[GID_4_IN1]);
  1349.         }
  1350.     break;
  1351.     default:
  1352.         if (page == 41 && code >= SCAN_1 && code <= SCAN_8)
  1353.         {   ActivateLayoutGadget(autodoc_gadgets[GID_4_LY1], MainWindowPtr, NULL, (Object) autodoc_gadgets[code - SCAN_1 + GID_4_ST5]);
  1354.         }
  1355.     break;
  1356.     }
  1357.  
  1358.     return(1);
  1359. }
  1360.  
  1361. AGLOBAL void autodoc2(void)
  1362. {   struct Hook    Hook4Struct;
  1363.     TEXT           GadTitle[MAXELEMENTS_4 + 1][VLONGFIELD + 1];
  1364.     ULONG          i, counter;
  1365.     struct TagItem tag_texteditor[4] =
  1366.     { { GA_ID,                    NULL                  }, // ti_Data filled later
  1367.       { GA_RelVerify,             TRUE                  },
  1368.       { GA_TEXTEDITOR_ExportWrap, 72,                   },
  1369.       { TAG_END,                  NULL                  },
  1370.     }, tag_subcaption[3] =
  1371.     { { LABEL_Text,               NULL                  }, // ti_Data filled later
  1372.       { LABEL_Justification,      LJ_CENTRE             },
  1373.       { TAG_END,                  NULL                  },
  1374.     }, tag_button[4] =
  1375.     { { GA_ID,                    GID_4_BU3             },
  1376.       { GA_RelVerify,             TRUE                  },
  1377.       { GA_Text,                  (ULONG) "_Other page" },
  1378.       { TAG_END,                  NULL                  }
  1379.     }, tag_supercaption[7] =
  1380.     { { LAYOUT_Orientation,       LAYOUT_ORIENT_VERT    },
  1381.       { LAYOUT_SpaceOuter,        TRUE                  },
  1382.       { LAYOUT_VertAlignment,     LALIGN_CENTER         },
  1383.       { LAYOUT_HorizAlignment,    LALIGN_CENTER         },
  1384.       { LAYOUT_BevelStyle,        BVS_NONE              },
  1385.       { LAYOUT_AddImage,          NULL                  }, // ti_Data filled later
  1386.       { TAG_END,                  NULL                  }
  1387.     }, tag_leftlayout[28] =
  1388.     { { LAYOUT_Orientation,       LAYOUT_ORIENT_VERT    },
  1389.       { LAYOUT_SpaceOuter,        TRUE                  },
  1390.       { LAYOUT_DeferLayout,       TRUE                  },
  1391.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1392.       { CHILD_WeightedHeight,     0                     },
  1393.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1394.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1395.       { CHILD_WeightedHeight,     0                     },
  1396.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1397.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1398.       { CHILD_WeightedHeight,     0                     },
  1399.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1400.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1401.       { CHILD_WeightedHeight,     0                     },
  1402.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1403.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1404.       { CHILD_WeightedHeight,     0                     },
  1405.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1406.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1407.       { CHILD_WeightedHeight,     0                     },
  1408.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1409.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1410.       { CHILD_WeightedHeight,     0                     },
  1411.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1412.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1413.       { CHILD_WeightedHeight,     0                     },
  1414.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1415.       { TAG_END,                  NULL                  },
  1416.     }, tag_rightlayout[25] =
  1417.     { { LAYOUT_Orientation,       LAYOUT_ORIENT_VERT    },
  1418.       { LAYOUT_SpaceOuter,        TRUE                  },
  1419.       { LAYOUT_DeferLayout,       TRUE                  },
  1420.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1421.       { CHILD_WeightedHeight,     0                     },
  1422.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1423.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1424.       { CHILD_WeightedHeight,     0                     },
  1425.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1426.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1427.       { CHILD_WeightedHeight,     0                     },
  1428.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1429.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1430.       { CHILD_WeightedHeight,     0                     },
  1431.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1432.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1433.       { CHILD_WeightedHeight,     0                     },
  1434.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1435.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1436.       { CHILD_WeightedHeight,     0                     },
  1437.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1438.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1439.       { CHILD_WeightedHeight,     0                     },
  1440.       { LAYOUT_AddChild,          NULL                  }, // ti_Data filled later
  1441.       { TAG_END,                  NULL                  },
  1442.     }, tag_bothlayout[8] =
  1443.     { { LAYOUT_Orientation,    LAYOUT_ORIENT_HORIZ   },
  1444.       { LAYOUT_SpaceOuter,     TRUE                  },
  1445.       { LAYOUT_DeferLayout,    TRUE                  },
  1446.       { LAYOUT_AddChild,       NULL                  }, // ti_Data filled later
  1447.       { CHILD_WeightedWidth,   50                    },
  1448.       { LAYOUT_AddChild,       NULL                  }, // ti_Data filled later
  1449.       { CHILD_WeightedWidth,   50                    },
  1450.       { TAG_END,               NULL                  }
  1451.     }, tag_rootlayout[7] =
  1452.     { { LAYOUT_Orientation,    LAYOUT_ORIENT_VERT    },
  1453.       { LAYOUT_SpaceOuter,     TRUE                  },
  1454.       { LAYOUT_DeferLayout,    TRUE                  },
  1455.       { LAYOUT_AddChild,       NULL                  }, // ti_Data filled later
  1456.       { LAYOUT_AddChild,       NULL                  }, // ti_Data filled later
  1457.       { CHILD_WeightedHeight,  0                     },
  1458.       { TAG_END,               NULL                  }
  1459.     }, tag_window[15] =
  1460.     { { WA_PubScreen,          NULL                  }, // ti_Data filled later
  1461.       { WA_ScreenTitle,        (ULONG) "Report+"                               },
  1462.       { WA_Title,              (ULONG) "Report+: Autodoc Editor (Page 2 of 2)" },
  1463.       { WA_Activate,           TRUE                  },
  1464.       { WA_DepthGadget,        TRUE                  },
  1465.       { WA_DragBar,            TRUE                  },
  1466.       { WA_CloseGadget,        TRUE                  },
  1467.       { WA_SizeGadget,         TRUE                  },
  1468.       { WA_IDCMP,              IDCMP_RAWKEY          },
  1469.       { WINDOW_IDCMPHook,      NULL                  }, // ti_Data filled later
  1470.       { WINDOW_IDCMPHookBits,  IDCMP_RAWKEY          },
  1471.       { WINDOW_MenuStrip,      NULL                  }, // ti_Data filled later
  1472.       { WINDOW_Position,       WPOS_FULLSCREEN       },
  1473.       { WINDOW_ParentGroup,    NULL                  }, // ti_Data filled later
  1474.       { TAG_END,               NULL                  }
  1475.     };
  1476.  
  1477.     strcpy(GadTitle[0], "_Function:");
  1478.     if (inputs)
  1479.     {   for (i = 1; i <= inputs; i++)
  1480.         {   strcpy(GadTitle[i], autodoc.var[i].name);
  1481.             strcat(GadTitle[i], ":");
  1482.     }   }
  1483.     if (returncode)
  1484.     {   strcpy(GadTitle[inputs + 1], "_Result:");
  1485.     }
  1486.     strcpy(GadTitle[inputs + 1 + returncode], "_Example:");
  1487.     strcpy(GadTitle[inputs + 2 + returncode], "_Notes:");
  1488.     strcpy(GadTitle[inputs + 3 + returncode], "_Bugs:");
  1489.     strcpy(GadTitle[inputs + 4 + returncode], "_See Also:");
  1490.  
  1491.     /* window
  1492.         root-layout
  1493.          both-layout
  1494.           left-layout
  1495.            super-caption
  1496.             sub-caption
  1497.            texteditor
  1498.           right-layout
  1499.            super-caption
  1500.             sub-caption
  1501.            texteditor
  1502.          button
  1503.          button */
  1504.  
  1505.     counter = 3;
  1506.     for (i = 0; i <= elements / 2; i++)
  1507.     {   tag_subcaption[0].ti_Data          = (ULONG) GadTitle[i];
  1508.         tag_texteditor[0].ti_Data          = GID_4_TE1 + i;
  1509.         tag_supercaption[5].ti_Data        = (ULONG) NewObjectA(LABEL_GetClass(),      NULL, tag_subcaption);
  1510.         tag_leftlayout[counter].ti_Data    = (ULONG) NewObjectA(LAYOUT_GetClass(),     NULL, tag_supercaption);
  1511.         counter += 2;
  1512.         tag_leftlayout[counter].ti_Data    =
  1513.         autodoc_gadgets[GID_4_TE1 + i]     = (ULONG) NewObjectA(TEXTEDITOR_GetClass(), NULL, tag_texteditor);
  1514.         counter++;
  1515.     }
  1516.     tag_leftlayout[counter].ti_Tag         = TAG_END;
  1517.     counter = 3;
  1518.     for (i = (elements / 2) + 1; i <= elements; i++)
  1519.     {   tag_subcaption[0].ti_Data          = (ULONG) GadTitle[i];
  1520.         tag_texteditor[0].ti_Data          = GID_4_TE1 + i;
  1521.         tag_supercaption[5].ti_Data        = (ULONG) NewObjectA(LABEL_GetClass(),      NULL, tag_subcaption);
  1522.         tag_rightlayout[counter].ti_Data   = (ULONG) NewObjectA(LAYOUT_GetClass(),     NULL, tag_supercaption);
  1523.         counter += 2;
  1524.         tag_rightlayout[counter].ti_Data   =
  1525.         autodoc_gadgets[GID_4_TE1 + i]     = (ULONG) NewObjectA(TEXTEDITOR_GetClass(), NULL, tag_texteditor);
  1526.         counter++;
  1527.     }
  1528.     tag_rightlayout[counter].ti_Tag         = TAG_END;
  1529.  
  1530.     tag_bothlayout[3].ti_Data   = (ULONG) NewObjectA(LAYOUT_GetClass(), NULL,            tag_leftlayout);
  1531.     tag_bothlayout[5].ti_Data   = (ULONG) NewObjectA(LAYOUT_GetClass(), NULL,            tag_rightlayout);
  1532.     tag_rootlayout[3].ti_Data   = (ULONG) NewObjectA(LAYOUT_GetClass(), NULL,            tag_bothlayout);
  1533.     tag_rootlayout[4].ti_Data   =
  1534.     autodoc_gadgets[GID_4_BU3]  = (ULONG) NewObjectA(NULL,              "button.gadget", tag_button);
  1535.     tag_window[13].ti_Data      =
  1536.     autodoc_gadgets[GID_4_LY2]  = (ULONG) NewObjectA(LAYOUT_GetClass(), NULL,            tag_rootlayout);
  1537.  
  1538.     InitHook(&Hook4Struct, Hook4Func, NULL);
  1539.     tag_window[9].ti_Data       = &Hook4Struct;
  1540.     lockscreen();
  1541.     tag_window[0].ti_Data       = (ULONG) ScreenPtr;
  1542.     gadtools();
  1543.     tag_window[11].ti_Data      = MenuPtr;
  1544.     WinObject[4]                = (ULONG) NewObjectA(WINDOW_GetClass(), NULL,             tag_window);
  1545.     unlockscreen();
  1546.     if (!WinObject[4]) // Object creation successful?
  1547.     {   rq("Can't create ReAction objects!");
  1548.     }
  1549.     openwindow();
  1550.     OnMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_SAVE,   NOSUB));
  1551.     OnMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_SAVEAS, NOSUB));
  1552.     /* New and Open... are not permitted from pages 14 and 42, since the
  1553.        opened document might need a different number of text editor
  1554.        gadgets. */
  1555.  
  1556.     // Do any necessary imports.
  1557.     SetGadgetAttrs
  1558.     (   autodoc_gadgets[GID_4_TE1], MainWindowPtr, NULL,
  1559.         GA_TEXTEDITOR_Contents,     autodoc.function
  1560.     );
  1561.     if (inputs)
  1562.     {   for (i = 1; i <= inputs; i++)
  1563.         {   SetGadgetAttrs
  1564.             (   autodoc_gadgets[GID_4_TE1 + i], MainWindowPtr, NULL,
  1565.                 GA_TEXTEDITOR_Contents, autodoc.var[i].desc
  1566.             );
  1567.     }   }
  1568.     if (returncode)
  1569.     {   SetGadgetAttrs
  1570.         (   autodoc_gadgets[GID_4_TE1 + inputs + 1], MainWindowPtr, NULL,
  1571.             GA_TEXTEDITOR_Contents, autodoc.var[0].desc
  1572.         ); // return code
  1573.     }
  1574.     SetGadgetAttrs
  1575.     (   autodoc_gadgets[GID_4_TE1 + inputs + returncode + 1], MainWindowPtr, NULL,
  1576.         GA_TEXTEDITOR_Contents, autodoc.example
  1577.     );
  1578.     SetGadgetAttrs
  1579.     (   autodoc_gadgets[GID_4_TE1 + inputs + returncode + 2], MainWindowPtr, NULL,
  1580.         GA_TEXTEDITOR_Contents, autodoc.notes
  1581.     );
  1582.     SetGadgetAttrs
  1583.     (   autodoc_gadgets[GID_4_TE1 + inputs + returncode + 3], MainWindowPtr, NULL,
  1584.         GA_TEXTEDITOR_Contents, autodoc.bugs
  1585.     );
  1586.     SetGadgetAttrs
  1587.     (   autodoc_gadgets[GID_4_TE1 + inputs + returncode + 4], MainWindowPtr, NULL,
  1588.         GA_TEXTEDITOR_Contents, autodoc.seealso
  1589.     );
  1590.  
  1591.     ActivateLayoutGadget(autodoc_gadgets[GID_4_LY2], MainWindowPtr, NULL, (Object) autodoc_gadgets[GID_4_TE1]);
  1592.     loop();
  1593.     closewindow();
  1594. }
  1595.  
  1596. MODULE ULONG parseeither(STRPTR terminator1, STRPTR terminator2)
  1597. {   ULONG dest = 0; // index in destination string
  1598.  
  1599. /* When this returns, offset points just past the end of the terminator
  1600. string. string contains what was found before the terminator string. */
  1601.  
  1602.     while (1)
  1603.     {   if (IOBuffer[offset] != CR)
  1604.         {   string[dest] = IOBuffer[offset];
  1605.         }
  1606.         if (!strncmp(&IOBuffer[offset], terminator1, strlen(terminator1)))
  1607.         {   string[dest] = 0;
  1608.             offset += strlen(terminator1);
  1609.             return(1);
  1610.         } elif (!strncmp(&IOBuffer[offset], terminator2, strlen(terminator2)))
  1611.         {   string[dest] = 0;
  1612.             offset += strlen(terminator2);
  1613.             return(2);
  1614.         } elif (offset > strlen(IOBuffer)) // we are past the end of the buffer
  1615.         {   string[0] = 0;
  1616.             return(0);
  1617.         } else
  1618.         {   offset++;
  1619.             if (IOBuffer[offset] != CR)
  1620.             {   dest++;
  1621. }   }   }   }
  1622.  
  1623. MODULE void numberofinputs(void)
  1624. {   ULONG i;
  1625.  
  1626.     if (autodoc.var[0].name[0])
  1627.         returncode = 1; // non-boolean as it's used mathematically
  1628.     else returncode = 0;
  1629.  
  1630.     inputs = 0;
  1631.     for (i = 1; i <= 8; i++)
  1632.     {   if (autodoc.var[i].name[0])
  1633.             inputs++;
  1634.         else break;
  1635.     }
  1636.     elements = inputs + 4 + returncode;
  1637. }
  1638.